package com.gemme.gemme.wode;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.util.StrUtil;
import com.gemme.gemme.view.RefreshView;
import com.gemme.gemme.view.Topview;
import com.google.android.material.tabs.TabLayout;
import com.jaeger.library.StatusBarUtil;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

//侧滑删除地址
public class XydRecordActivity extends BaseActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xyd_record);
        initTop();
        initView();
        getData();
    }

    public void getData(){
        String url = DataManager.BaseUrl_yanglinyu + "mall/shopwish/app/exchange/record?current=1&size=100";

        HashMap<String, String> headMap = new HashMap<>();
        headMap.put(DataManager.AuthorizationKey,DataManager.getToken(this));
        DataManager.toServer3(this, url, DataManager.GET_TYPE, "", headMap, new DataManager.GeResponse() {
            @Override
            public void onResponse(String response) {
              try {
                  System.out.println("");
                  XydBean xydBean = JSON.parseObject(response, XydBean.class);
                  List<XydBean.DataBean.RecordsBean> records = xydBean.getData().getRecords();
                  refreshView.setAdapter(new XydDuihuanAdapter(records));
              }catch (Exception e){

              }
            }
        });
    }
    RefreshView refreshView;
    private void initView() {

        refreshView = findViewById(R.id.refreshView);
        refreshView.setLayoutManager(new LinearLayoutManager(this));

    }


    private void initTop() {
//        StatusBarUtil.setColor(this,getResources().getColor(R.color.white_color) );
        StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setTranslucent(this,250);
        Topview topview = findViewById(R.id.topview);
        topview.setContentText("心愿单兑换列表");
    }


    public class XydDuihuanAdapter extends RecyclerView.Adapter<XydDuihuanAdapter.ViewHolder>{


        private List<XydBean.DataBean.RecordsBean> records;

        public XydDuihuanAdapter(List<XydBean.DataBean.RecordsBean> records) {

            this.records = records;
        }

        @NonNull
        @Override
        public XydDuihuanAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
            //adapter_address
            View inflate = LayoutInflater.from(viewGroup.getContext()).
                    inflate(R.layout.xyd_duihuan_item, null);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            inflate.setLayoutParams(layoutParams);
            return new XydDuihuanAdapter.ViewHolder(inflate);
        }

        @Override
        public void onBindViewHolder(@NonNull XydDuihuanAdapter.ViewHolder holder, int position) {
           try {
               XydBean.DataBean.RecordsBean recordsBean = records.get(position);
               Object finishTime = recordsBean.getFinishTime();

               holder.tv_desc.setText("成功兑换"+recordsBean.getProductName());
               holder.tv_time.setText(StrUtil.noNUll(finishTime).substring(0,11));
           }catch (Exception e){

           }
        }

        @Override
        public int getItemCount() {
            return records.size();
        }


        public class ViewHolder extends RecyclerView.ViewHolder {
            TextView tv_time;
            TextView tv_desc;
            public ViewHolder(@NonNull View itemView) {
                super(itemView);
                tv_time = itemView.findViewById(R.id.tv_time);
                tv_desc = itemView.findViewById(R.id.tv_desc);
            }
        }
    }




}